﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace SCM.API.Write
{
    public class GlobalExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<GlobalExceptionFilter> logger;

        public GlobalExceptionFilter(ILogger<GlobalExceptionFilter> logger)
        {
            this.logger = logger;
        }
        public void OnException(ExceptionContext context)
        {
            //1.把错误记下来
            logger.LogError("发生全局异常:" + context.Exception.Message);
            //2.把错误标记未已处理
            context.ExceptionHandled = true;
        }
    }
}
